home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / Security - care / Protect / Tonto / pathname.c < prev    next >
Text File  |  1991-11-26  |  2KB  |  72 lines

  1. /* Path names 
  2.  * Copyright 1988 Greg Coleman
  3.  * These sources may be freely distributed provided this notice
  4.  * remains intact.
  5.  */
  6.  
  7. # define    mfsSigWord    0xd2d7;
  8. # define    hfsSigWord    0x4244;
  9. # define    rootDirID    2
  10. # include <Files.h>
  11. # include "Tonto.h"
  12. /*
  13.  * Given a partial path name and a volume (or working directory)
  14.  * reference number, construct an absolute path up to, but not
  15.  * including, the partial path.
  16.  * The input partial path string is replaced.
  17.  * The third parameter is the length of the string buffer.
  18.  */
  19. StringPtr
  20. pathname(pname, vRefNum, n)
  21.     StringPtr    pname;
  22.     Integer        vRefNum;
  23.     int            n;
  24. {
  25.     OSErr        result;
  26.     int            m;                    /* length so far */
  27.      CInfoPBRec    ci;
  28.      Str255        dname;                /* path component name */
  29.      Str255        tname;                /* temp space */
  30. #define    dp        ci.dirInfo
  31.  
  32.     if (n > sizeof(tname))
  33.         n = sizeof(tname);
  34.     m = pname[0];
  35.     if (m == 0) {
  36.         return;
  37.     }
  38.     /*
  39.      * Find the folder containing the supplied file/folder
  40.      */
  41.     ZERO(ci);
  42.     ci.hFileInfo.ioNamePtr = pname;
  43.     ci.hFileInfo.ioVRefNum = vRefNum;
  44.     result = PBGetCatInfo(&ci, FALSE);
  45.  
  46.     pname[0] = m = 0;
  47.      dp.ioNamePtr = dname;
  48.      
  49.     if (result == noErr)
  50.     {
  51.         do
  52.         {
  53.             dp.ioDrDirID = dp.ioDrParID;
  54.              dp.ioDrParID = 0;
  55.              dp.ioFDirIndex = -1;
  56.             dname[0] = '\0';
  57.             if (result = PBGetCatInfo(&ci,0))
  58.                 break;
  59.  
  60.             if (m + dname[0] >= n) {
  61.                 pname[0] = 0;
  62.                 break;
  63.             }
  64.             pstrcat2 (tname, (SP)"\p:", pname);
  65.             pstrcat2 (pname, dname, tname);
  66.             m = pname[0];
  67.         } while (dp.ioDrDirID != rootDirID);
  68.         if (pname[m] == ':')
  69.             pname[0] = --m;
  70.     }
  71.     return pname;
  72. }